package com.atwork.wuhua.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.atwork.wuhua.ConstantsMyself;
import com.atwork.wuhua.R;
import com.atwork.wuhua.adapter.CommunityAdapter;
import com.atwork.wuhua.base.BaseActivity;
import com.atwork.wuhua.bean.CommunityBean;
import com.atwork.wuhua.utils.LogUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MyCollectionActivity extends BaseActivity {
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.rv_collection)
    RecyclerView rvCollection;

    private CommunityAdapter communityAdapter;

    private List<CommunityBean> communityBeans;

    public static final String COLLECTION = "1";
    public static final String MESSAGE = "2";
    private String mType = "1"; //我的收藏 or 我的发帖

    @Override
    protected boolean isBindEventBus() {
        return false;
    }

    @Override
    public int intiLayout() {
        return R.layout.activity_my_collection;
    }

    @Override
    public void initView() {
        mType = getIntent().getExtras().getString(ConstantsMyself.INTENTTYPE);
        if (COLLECTION.equals(mType)) {
            tvTitle.setText("我的收藏");

        } else if (MESSAGE.equals(mType)) {
            tvTitle.setText("我的发帖");
        }


        communityBeans = new ArrayList<>();
        List<CommunityBean.DataBean> dataBeans = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            dataBeans.clear();
            for (int j = 0; j < 9; j++) {
                CommunityBean.DataBean dataBean = new CommunityBean.DataBean();
                dataBean.setThumb("http://im5.leaderhero.com/wallpaper/20140328/7afa04d2-4.jpg");
                dataBeans.add(dataBean);
            }
            communityBeans.add(new CommunityBean(i + "", dataBeans, i + ""));
        }
    }

    @Override
    public void initData() {
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        rvCollection.setLayoutManager(manager);
        communityAdapter = new CommunityAdapter(this, R.layout.item_community, communityBeans);
        rvCollection.setAdapter(communityAdapter);

        communityAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intent = null;
                switch (view.getId()) {
                    case R.id.img_thumb:
                        LogUtils.e("个人详情");
                        intent = new Intent(MyCollectionActivity.this, PersonInfoActivity.class);
                        intent.putExtra(ConstantsMyself.INTENTID, position + "");
                        startActivity(intent);
                        break;
                    case R.id.tv_content:
                        LogUtils.e("内容");
                        break;
                    case R.id.lly_zan:
                        LogUtils.e("点赞");
                        break;
                    case R.id.lly_comment:
                        LogUtils.e("评论");
                        break;
                    case R.id.lly_collection:
                        LogUtils.e("收藏");
                        break;
                }
            }
        });

    }


    @OnClick(R.id.img_left)
    public void onViewClicked() {
        finish();
    }
}
